package <package name>
 
import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}
import java.util.{Date, Properties}
// import java.time
 
object KafkaTodd{
  def main(args: Array[String]):Unit={
    println("start------")
    val topic="test_topic"
    val brokers="127.0.0.1:9092"
    val now=new Date()
 
    val props=new Properties()
    props.put("bootstrap.servers", brokers)
    props.put("client.id", "0")
    props.put("key.serializer",   "org.apache.kafka.common.serialization.StringSerializer")
    props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")
    val producer=new KafkaProducer[String, String](props)
    val rcd=new ProducerRecord[String, String](topic, now.toString())
    producer.send(rcd)
    // 这里必须要调结束，否则kafka那边收不到消息 
    producer.close()
 
  }
}